""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Maintainer: Stephen Morrow (yawmark)
"             http://yawmark.com - steve@yawmark.com
"
" Derived from amix.dk -> http://amix.dk/vim/vimrc.html
" Version 0.9 - 2012-03-31 11:00
"
" http://code.google.com/p/yawmark-vim/
"
" How_to_Install_on_Linux:
"    $ cd ~
"    $ svn co https://yawmark-vim.googlecode.com/svn/runtime/ .vim
"    $ ./install-vimrc.sh
"
" How_to_Install_on_Windows:
"    > cd %UserProfile%
"    > svn co https://yawmark-vim.googlecode.com/svn/runtime/ .vim
"    > ./install-vimrc.bat
"
" How_to_Upgrade:
"    $ svn update ~/.vim
"
" Sections:
"    -> General
"    -> Vim_User_Interface
"    -> Colors_and_Fonts
"    -> Moving_Around
"    -> Buffer_Management
"    -> Files_and_Backups
"    -> Tabs_and_Indent
"    -> Editing_Mappings
"
" Revisions:
"    > 0.10: Added shortcut for "quick-save" <F5>
"    > 0.9:  Made diffsplit vertical by default
"    > 0.8:  Added MRU (Most Recently Used) plugin mapped to <F9>
"    > 0.7:  Added shortcut for easy printing <S-F12>
"    > 0.6:  Minor changes for buffer and tab management
"    > 0.5:  Add function to toggle line numbers with F2
"    > 0.4:  Fix console display problems (esp. in Cygwin)
"    > 0.3:  Time to call this an update. Numerous minor configuration changes
"    > 0.2:  Better management of Vim configuration
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Don't use vi-compatible mode
set nocompatible

" Enable plugin bundle management
filetype off
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()

" Enable filetype plugin
filetype plugin indent on

" Prevent arbitrary command execution vulnerability
" http://www.securityfocus.com/bid/14374/references
set modelines=0

" Set to autoread when file is changed outside of Vim
set autoread

" Enable wrap toggling
command! -nargs=* Wrap set wrap linebreak nolist
nnoremap <leader>w :set nowrap! nolinebreak! nolist<cr>

" Fast editing of the Vim configuration file
map <S-F5> :e ~/.vim/vimrc_core.vim<cr>

" When Vim configuration fie is edited, reload it
if has("win32")
	au! bufwritepost vimrc_core.vim so ~\.vim\vimrc_core.vim
else
	au! bufwritepost vimrc_core.vim so ~/.vim/vimrc_core.vim
endif

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Vim_User_Interface
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Use the "system clipboard"
set cb=unnamed

" Always show the current position
set ruler

" Minimize distractions by maximizing the Vimness
if has("gui_running")
    if has("win32")
        au GUIEnter * simalt ~x
    else
        set lines=999 columns=999
    endif
endif

" Change buffers without having to save
set hidden

" Make it easier to find the cursor by highlighting the current line
if has("gui_running")
    set cursorline
endif

" Ensure proper behavior for the backspace key
set backspace=indent,eol,start

" Make search expressions "very magic"
nnoremap / /\v
vnoremap / /\v

" Be smart about case-sensitive searches
set ignorecase
set smartcase

" By default, match every occurrence in a line, not just the first one
set gdefault

" Match while you type your search criteria
set incsearch

" Call attention to the matching bracket
set showmatch

" Highlight all matches
set hlsearch

" Makes it easy to turn off highlighted matches
nnoremap <leader><space> :noh<cr>

" Split diff screens vertically by default
set diffopt=vertical,filler

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => *Colors_and_Fonts*
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable syntax highlighting
syntax on

" Set font according to system
if has("win32")
    set gfn=Consolas:h10:cANSI
else
    set gfn=Monospace\ 10
    set shell=/bin/bash
endif

" Set color scheme based on UI
if has("gui_running")
	set go-=T " remove toolbar
	set go-=r " remove scrollbar
	set t_Co=256
	set background=dark
	color phd
else
	color peaksea
	set background=dark
endif

set encoding=utf-8
try
	lang en_US
catch
endtry

" Default file types
set ffs=unix,dos,mac

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Moving_Around
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Make navigation between window splits easier
map <C-j> <C-w>j<C-w>_
map <C-k> <C-w>k<C-w>_
map <C-h> <C-w>h<C-w>
map <C-l> <C-w>l<C-w>

" Make it easy to create a new tab
map <leader>tn :tabnew<cr>

" Relative line numbers are convenient for non-:ex movements
function! ToggleLineNumbers()
    if &nu
        set rnu
    else
        set nu
    endif
endfunction
:nnoremap <silent> <F2> :call ToggleLineNumbers()<cr>
set rnu

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Buffer_Management
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Use the arrows for something useful, like moving among buffers
map <right> :bn<cr>
map <left> :bp<cr>

" Easier buffer selection by number
:nnoremap <F4> :ls<cr>:b<Space>

" Follow the open buffer
set autochdir

" Close the current buffer like TextPad
map <C-F4> :bd<cr>

" Easy printing
map <S-F12> :hardcopy<cr>

" Fast saving with "\s"
nmap <leader>s :w!<cr>

" Quick save with <F5>
:inoremap <F5> <c-o>:w!<cr>
:nnoremap <F5> :w!<cr>

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files_and_Backups
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Rely on version control more than Vim backups
" set nobackup
" set nowb
" set noswapfile

" Persistent undo
" try
" 	if has("win32")
" 		set undodir=C:\Windows\Temp
" 	else
" 		set undodir=~/.vim/undodir
" 	endif
" 	set undofile
" catch
" endtry

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Tabs_and_Indent
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set autoindent
set smartindent

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Editing_Mappings
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Strip all trailing whitespace in the current file
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<cr>

